﻿<%@ Page Title="" Language="C#" MasterPageFile="~/manager/page/ManagerMasterPage.Master" AutoEventWireup="true" CodeBehind="addstore.aspx.cs" Inherits="Com.Web.coffinegurunaru.manager.store.addstore" %>
<%@ Register TagPrefix="UC" TagName="Menu" Src="~/manager/store/menu.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="phHead" runat="server">
<script type="text/javascript" src="http://openapi.map.naver.com/js/naverMap.naver?key=<%=NaverAPI.GetAPIKey()%>"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="phContent" runat="server">
<hr />
<br />
<table width="100%" border="0">
<tr>
	<td valign="top" width="60">
<UC:Menu ID="Menu1" SubPageType=1 runat="server" />
	</td>
	<td style="width:20px;"></td>
	<td valign="top">
		<table width="100%" height="100%" border="0">
		<tr>
			<td id="m_UserList" valign="top" style="width:400px;">
				[가맹점 회원 리스트]
				<table cellpadding="0" cellspacing="1" style="background-color:Gray; width:400;" class="m_UserList">
				<tr>
					<td></td>
				</tr>
				</table>
				<table style="width:100%; height:30px;">
				<tr>
					<td style="text-align:center;">
					<div id="m_Pager"></div>
					</td>
				</tr>
				</table>
			</td>
			<td style="width:10px;"></td>
			<td valign="top" id="m_StoreInput">
				<table cellpadding="0" cellspacing="1" style="background-color:White; width:520;" class="m_UpdateStore">
				<tr style="height:30px;">
					<td style="background-color:#eeeeee; width:100px; text-align:center;">아이디</td>
					<td style="background-color:White; width:400px; text-align:left;"><input type="text" class="m_UserID"  style="width:120px" /></td>
				</tr>
				<tr style="height:30px;">
					<td style="background-color:#eeeeee; width:100px; text-align:center;">가맹점명</td>
					<td style="background-color:White; width:400px; text-align:left;"><input type="text" class="m_StoreName"  style="width:120px" /></td>
				</tr>
				<tr style="height:30px;">
					<td style="background-color:#eeeeee; width:100px; text-align:center;">오픈일</td>
					<td style="background-color:White; width:400px; text-align:left;"><input type="text" class="m_OpenDate"  style="width:120px" /></td>
				</tr>
				<tr style="height:30px;">
					<td style="background-color:#eeeeee; text-align:center;">사업자번호</td>
					<td style="background-color:White; text-align:left;"><input type="text" class="m_CompanyNo1" style="width:80px" />-<input type="text" class="m_CompanyNo2" style="width:80px" />-<input type="text" class="m_CompanyNo3" style="width:80px" /></td>
				</tr>
				<tr style="height:30px;">
					<td style="background-color:#eeeeee; text-align:center;">전화번호</td>
					<td style="background-color:White; text-align:left;"><input type="text" class="m_Phone1" style="width:80px" />-<input type="text" class="m_Phone2" style="width:80px" />-<input type="text" class="m_Phone3" style="width:80px" /></td>
				</tr>
				<tr style="height:80px;">
					<td style="background-color:#eeeeee; text-align:center;">주소</td>
					<td style="background-color:White; text-align:left;"><input type="text" class="m_PostNo1" style="width:80px" readonly="readonly" />-<input type="text" class="m_PostNo2" style="width:80px" readonly="readonly" />&nbsp;&nbsp;<input type="button" class="m_btnPostSearch" value="우편번호검색" /><br />
					<input type="text" class="m_Address"  style="width:400px"/><br />
					Naver 지도 좌표 X : <input type="text" class="m_PointX"  style="width:80px" readonly="readonly"/>&nbsp;&nbsp;&nbsp; Y : <input type="text" class="m_PointY"  style="width:80px" readonly="readonly"/>
					<input type="button" value="지도검색" class="m_NaverMapSearch" />
					</td>
				</tr>
				<tr style="height:30px;">
					<td style="background-color:#eeeeee; text-align:center;">지역</td>
					<td style="background-color:White; text-align:left;"><input type="text" class="m_CityName" style="width:200px" /></td>
				</tr>
				<tr style="height:30px;">
					<td style="background-color:#eeeeee; text-align:center;">테이크아웃</td>
					<td style="background-color:White; text-align:left;">
						<select class="m_IsTakeout" style="width:80px" >
						<option value="1">가능</option>
						<option value="2">불가능</option>
						<option value="3">기타</option>
						</select>
						<input type="text" class="m_Takeout" style="display:none;" />
					</td>
				</tr>
				<tr style="height:30px;">
					<td style="background-color:#eeeeee; text-align:center;">주차여부</td>
					<td style="background-color:White; text-align:left;"><select class="m_IsParking" style="width:80px" >
						<option value="1">가능</option>
						<option value="2">불가능</option>
						<option value="3">기타</option>
						</select>
						<input type="text" class="m_Parking" style="display:none;" />
					</td>
				</tr>
				<tr style="height:30px;">
					<td style="background-color:#eeeeee; text-align:center;">매장크기</td>
					<td style="background-color:White; text-align:left;"><input type="text" class="m_StoreSize" style="width:200px" /></td>
				</tr>
				<tr style="height:30px;">
					<td style="background-color:#eeeeee; text-align:center;">오픈시간</td>
					<td style="background-color:White; text-align:left;"><input type="text" class="m_OpenTime" style="width:200px" /></td>
				</tr>
				<tr style="height:200px;">
					<td style="background-color:#eeeeee; text-align:center;">설명</td>
					<td style="background-color:White; text-align:left;"><textarea class="m_Desc" cols="1" rows="1" style="width:400px; height:180px;"></textarea>
					
					</td>
				</tr>
				<tr>
					<td style="background-color:#eeeeee; text-align:center;">파일</br></br><input type="button" value="이미지추가" style="width:80px;" id="btnImageAdd"/></td>
					<td style="height:100px;" class="m_FileList"><table><tr></tr></table></td>
				</tr>
				<tr>
					<td colspan="2" align="center"><input type="button" value="저장" style="width:150px;" id="m_btnStoreSave"/></td>
				</tr>
				</table>
				<div id="m_NaverAddrList" style="width:520px; height:200px; overflow:scroll" ></div><br />
				<div id="m_MapContainer" style="width:600px; height:400px;"></div>
			</td>
		</tr>
		</table>

	</td>
</tr>
</table>
<script language="javascript" type="text/javascript">
(function($) {
	$.NewStore = {};

	$.NewStore = {
		
		Init : function() {
			$("#m_Pager").pager({
				pageSize : 30,
				useCallback : true,
				pageNo : 1,
				callback:function(pageNo) {
					$.NewStore.NewUserList();
				}
			});

			$.NewStore.NewUserList();
			
			$("#m_MoreList").click(function() {
			});
			
			$("#m_btnStoreSave").click(function() {
				$.NewStore.Save();
			});
			
			$("#m_StoreInput>table.m_UpdateStore select.m_IsTakeout").change(function() {
				if ( $(this).val() == "3" )
					$("#m_StoreInput>table.m_UpdateStore input.m_Takeout").show()
				else
					$("#m_StoreInput>table.m_UpdateStore input.m_Takeout").hide()
			});
			
			$("#m_StoreInput>table.m_UpdateStore select.m_IsParking").change(function() {
				if ( $(this).val() == "3" )
					$("#m_StoreInput>table.m_UpdateStore input.m_Parking").show()
				else
					$("#m_StoreInput>table.m_UpdateStore input.m_Parking").hide()
			});
			
			$("#m_StoreInput>table.m_UpdateStore input.m_btnPostSearch").click(function() {
				$.manager.postopen("$.NewStore.SetPost");
			});
			
			$("#m_StoreInput>table.m_UpdateStore input.m_NaverMapSearch").click(function() {
				if ( $("#m_StoreInput>table.m_UpdateStore input.m_PostNo1").val() == "" )
				{
					alert( "주소를 입력하세요." );
					return false;
				}
				
				if ( $("#m_StoreInput>table.m_UpdateStore input.m_Address").val() == "" )
				{
					alert( "주소를 입력하세요." );
					return false;
				}
				
				$("#m_NaverAddrList").ajaxNet(
				"/manager/store/storemethod.aspx?_vb=GetNaverAddr",
				{
					"Address": $("#m_StoreInput>table.m_UpdateStore input.m_Address").val()
				}, function(results, context) {
					$("#m_NaverAddrList").html(results);
					$("#m_NaverAddrList").find("tr").click(function() {
						var $tr = $(this);
						var address = $tr.find("td:eq(0)").text();
						var pointX = $tr.find("td:eq(1)").text();
						var pointY = $tr.find("td:eq(2)").text();
						$.NewStore.NaverMapViewr(pointX, pointY, address);
						$("#m_StoreInput>table.m_UpdateStore input.m_PointX").val(pointX);
						$("#m_StoreInput>table.m_UpdateStore input.m_PointY").val(pointY);
					});
				});
			});
			
			$("#btnImageAdd").click(function() {
			
				if ( $("#m_StoreInput>table.m_UpdateStore td.m_FileList table tr td").size() >= 5 )
				{
					alert("이미지는 5개까지 첨부할수 있습니다." );
					return;
				}
				$.manager.fileopen(7, "$.NewStore.Callback");
			});
		},
		
		SetPost : function(postno1, postno2, address )
		{
			$("#m_StoreInput>table.m_UpdateStore input.m_PostNo1").val(postno1);
			$("#m_StoreInput>table.m_UpdateStore input.m_PostNo2").val(postno2);
			$("#m_StoreInput>table.m_UpdateStore input.m_Address").val(address).focus().select();
			
		},
		
		MapObj : null,
		markObj : null,
		infoWin : null,
		NaverMapViewr : function(PointX, PointY, address)
		{
			$("#m_MapContainer").show();
			var opts = {width:600, height:400, mapMode:0};
			var point = new NPoint(PointX,PointY);
			if ( $.NewStore.MapObj != null )
			{
				$.NewStore.MapObj.clearOverlays();
				$.NewStore.MapObj.setCenter(point ,2);
			}
			else
			{
				$.NewStore.MapObj = new NMap(document.getElementById('m_MapContainer'),opts);
				$.NewStore.MapObj.setCenterAndZoom(point ,2);
			}
			
			/* 지도 컨트롤 생성 */
			var zoom = new NZoomControl();
			zoom.setAlign("left"); zoom.setValign("top");
			$.NewStore.MapObj.addControl(zoom);

			/* 지도 좌표, 축적 수 준 초기화 */
			var iconURL = "/images/coffine.jpg";
			var iconSize = new NSize(30, 30);
			var icon = new NIcon(iconURL, iconSize)
			
			
			/* 지도 모드 변경 버튼 생성 */
			var mapBtns = new NMapBtns();
			mapBtns.setAlign("right"); mapBtns.setValign("top");
			$.NewStore.MapObj.addControl(mapBtns);
			
			// 아이콘 표시 //
			$.NewStore.markObj = new NMark(point, icon);
			$.NewStore.MapObj.addOverlay( $.NewStore.markObj );
			
			$.NewStore.infowin = new NInfoWindow();
			$.NewStore.MapObj.addOverlay($.NewStore.infowin);
			NEvent.addListener($.NewStore.markObj, "mouseover", function(pos) {
					$.NewStore.infowin.set(pos, '<div style="width:100px; height:50px; background-color:#ffffff; border:solid 1px #666666;">' + address + '</div>');
					$.NewStore.infowin.showWindow()
			});
			NEvent.addListener($.NewStore.markObj, "mouseout", function() {
					$.NewStore.infowin.hideWindow();
			});
		},
		
		NewUserList : function() {
			$("#m_UserList").ajaxNet(
			"/manager/store/storemethod.aspx?_vb=GetNewStore",
			{
				"PageNo": $("#m_Pager").pager("option", "currentPageNo")
			,	"PageSize" : $("#m_Pager").pager("option", "pageSize")
			}, function(results, context) {
				$("#m_UserList>table.m_UserList>tbody").html($(results[0]))
					$("#m_UserList>table.m_UserList>tbody").find("input.m_btnAdd").click(function() {
						$.NewStore.InputStore($(this).closest("tr"));
					})
					.end().find("input.m_btnUnActive").click(function() { 
						if ( confirm("정말로 제외하시겠습니까?" ) ) {
							$.NewStore.SetActive($(this).closest("tr"));
						}
					});
				$("#m_Pager").pager("update", results[1]);
			});
		},
		
		SetActive : function( $tr )
		{
			var data = $tr.tagdata();
			var UserID = data.UserID;
			$tr.ajaxNet(
			"/manager/store/storemethod.aspx?_vb=SetStoreActive",
			{
				"UserID": UserID
			,	"IsActive": "N"
			}, function(results, context) {
				location.href = location.href;
				$tr.remove();
			});
		},
		
		InputStore : function( $tr )
		{
			$tr.parent().find("tr:gt(0)").css({"background-color":"#ffffff"}).removeClass("current");
			$tr.css({"background-color":"#eeeeee"}).addClass("current");
			var UserID = $tr.find("td:eq(0)").text();
			var UserName = $tr.find("td:eq(1)").text();
			$("#m_StoreInput>table.m_UpdateStore").tagdata().UserID = UserID;
			$("#m_StoreInput>table.m_UpdateStore input.m_UserID").val( UserID );
			$("#m_StoreInput>table.m_UpdateStore input.m_StoreName").val( UserName );
		},
		
		Callback : function( url )
		{
			$("#m_StoreInput>table.m_UpdateStore td.m_FileList table tr").append(
				$("<td align='center'><img src='" + url + "' width='80' height='80' /><input type='hidden' class='m_ImageURL' value='" + url + "'/><br/><a href='#' onclick='$.NewStore.ImageRemove(this); return false;'>삭제</a></td>")
			);
		},
		
		ImageRemove : function( elem )
		{
			if ( confirm("이미지를 삭제하시겠습니까?" ) )
				$(elem).closest("td").remove();
		},
		
		Save : function() {
			var UserID = $("#m_StoreInput>table.m_UpdateStore input.m_UserID").val();
			if ( UserID == undefined || UserID == "" )
			{
				alert( "가맹점을 선택하세요" );
				return false;
			}
			var StoreName = $("#m_StoreInput>table.m_UpdateStore input.m_StoreName").val();

			var CompanyNo1 = $("#m_StoreInput>table.m_UpdateStore input.m_CompanyNo1").val();
			var CompanyNo2 = $("#m_StoreInput>table.m_UpdateStore input.m_CompanyNo2").val();
			var CompanyNo3 = $("#m_StoreInput>table.m_UpdateStore input.m_CompanyNo3").val();
			
			var Phone1 = $("#m_StoreInput>table.m_UpdateStore input.m_Phone1").val();
			var Phone2 = $("#m_StoreInput>table.m_UpdateStore input.m_Phone2").val();
			var Phone3 = $("#m_StoreInput>table.m_UpdateStore input.m_Phone3").val();
			
			var PostNo1 = $("#m_StoreInput>table.m_UpdateStore input.m_PostNo1").val();
			var PostNo2 = $("#m_StoreInput>table.m_UpdateStore input.m_PostNo2").val();
			var Address = $("#m_StoreInput>table.m_UpdateStore input.m_Address").val();
			var CityName = $("#m_StoreInput>table.m_UpdateStore input.m_CityName").val();

			var IsTakeout = $("#m_StoreInput>table.m_UpdateStore select.m_IsTakeout").val();
			var Takeout = $("#m_StoreInput>table.m_UpdateStore input.m_Takeout").val();
			var IsParking = $("#m_StoreInput>table.m_UpdateStore select.m_IsParking").val();
			var Parking = $("#m_StoreInput>table.m_UpdateStore input.m_Parking").val();
			
			var StoreSize = $("#m_StoreInput>table.m_UpdateStore input.m_StoreSize").val();
			var OpenDate = $("#m_StoreInput>table.m_UpdateStore input.m_OpenDate").val();
			var OpenTime = $("#m_StoreInput>table.m_UpdateStore input.m_OpenTime").val();
			
			var PointX = $("#m_StoreInput>table.m_UpdateStore input.m_PointX").val();
			var PointY = $("#m_StoreInput>table.m_UpdateStore input.m_PointY").val();
			
			var Desc = $("#m_StoreInput>table.m_UpdateStore textarea.m_Desc").val();
			var ImageURLS = "";

			$("#m_StoreInput>table.m_UpdateStore td.m_FileList table tr td").each(function() {
				ImageURLS += ImageURLS == "" ? "" : ",";
				ImageURLS += $(this).find("input.m_ImageURL").val();
			});
			
			if ( $.trim( StoreName ) == "" ) {
				alert( "이름을 입력하세요");
				$("#m_StoreInput>table.m_UpdateStore input.m_StoreName").focus();
				return false;
			}
			
			if ( $.trim( Phone1 ) == "" ) {
				alert( "전화번호를 입력하세요");
				$("#m_StoreInput>table.m_UpdateStore input.m_Phone1").focus();
				return false;
			}
			if ( $.trim( Phone2 ) == "" ) {
				alert( "전화번호를 입력하세요");
				$("#m_StoreInput>table.m_UpdateStore input.m_Phone2").focus();
				return false;
			}
			if ( $.trim( Phone3 ) == "" ) {
				alert( "전화번호를 입력하세요");
				$("#m_StoreInput>table.m_UpdateStore input.m_Phone3").focus();
				return false;
			}
			
			if ( $.trim( PostNo1 ) == "" ) {
				alert( "주소를 입력하세요");
				$("#m_StoreInput>table.m_UpdateStore input.m_PostNo1").focus();
				return false;
			}
			if ( $.trim( PostNo2 ) == "" ) {
				alert( "주소를 입력하세요");
				$("#m_StoreInput>table.m_UpdateStore input.m_PostNo2").focus();
				return false;
			}
			if ( $.trim( Address ) == "" ) {
				alert( "주소를 입력하세요");
				$("#m_StoreInput>table.m_UpdateStore input.m_Address").focus();
				return false;
			}
			
			if ( $.trim( CityName ) == "" ) {
				alert( "지역을 입력하세요");
				$("#m_StoreInput>table.m_UpdateStore input.m_CityName").focus();
				return false;
			}

			$("#m_StoreInput").ajaxNet(
			"/manager/store/storemethod.aspx?_vb=CreateStore",
			{
				"UserID": UserID
			,	"IsActive": "Y"
			,	"StoreName": StoreName
			,	"CompanyNo": CompanyNo1 + "-" + CompanyNo2 + "-" + CompanyNo3
			,	"Phone": Phone1 + "-" + Phone2 + "-" + Phone3
			,	"PostNo": PostNo1 + "-" + PostNo2
			,	"Address": Address
			,	"CityName": CityName
			,	"IsTakeout": IsTakeout
			,	"Takeout": Takeout
			
			,	"IsParking": IsParking
			,	"Parking": Parking
			
			,	"StoreSize": StoreSize
			,	"OpenDate": OpenDate
			
			,	"PointX": PointX
			,	"PointY": PointY
			
			,	"OpenTime": OpenTime
			,	"Description": Desc
			}, function(results, context) {
				var StoreNo = results;
				
				if ( ImageURLS != "" )
				{
					$("#m_StoreInput>table.m_UpdateStore td.m_FileList").ajaxNet(
					"/manager/store/storemethod.aspx?_vb=CreateImage",
					{
						"StoreNo": StoreNo
					,	"ImageURLs": ImageURLS
					}, function(results, context) {
						location.href = location.href;
					});
				}
				/*
				$("#m_StoreInput>table.m_UpdateStore td.m_FileList table tr td").remove();
				
			
				$("#m_StoreInput>table.m_UpdateStore").tagdata().UserID = "";
				
				$("#m_StoreInput>table.m_UpdateStore input.m_StoreName").val( "" );
				$("#m_StoreInput>table.m_UpdateStore input.m_CompanyNo1").val( "" );
				$("#m_StoreInput>table.m_UpdateStore input.m_CompanyNo2").val( "" );
				$("#m_StoreInput>table.m_UpdateStore input.m_CompanyNo3").val( "" );
				
				$("#m_StoreInput>table.m_UpdateStore input.m_Phone1").val( "" );
				$("#m_StoreInput>table.m_UpdateStore input.m_Phone2").val( "" );
				$("#m_StoreInput>table.m_UpdateStore input.m_Phone3").val( "" );
				
				$("#m_StoreInput>table.m_UpdateStore input.m_PostNo1").val( "" );
				$("#m_StoreInput>table.m_UpdateStore input.m_PostNo2").val( "" );
				
				$("#m_StoreInput>table.m_UpdateStore input.m_Address").val( "" );
				$("#m_StoreInput>table.m_UpdateStore input.m_CityName").val( "" );
				
				$("#m_StoreInput>table.m_UpdateStore select.m_IsTakeout").val( "1");
				$("#m_StoreInput>table.m_UpdateStore input.m_Takeout").val( "" );
				$("#m_StoreInput>table.m_UpdateStore select.m_IsParking").val( "1");
				$("#m_StoreInput>table.m_UpdateStore input.m_Parking").val( "" );
				
				$("#m_StoreInput>table.m_UpdateStore input.m_StoreSize").val( "" );
				$("#m_StoreInput>table.m_UpdateStore input.m_OpenDate").val( "" );
				$("#m_StoreInput>table.m_UpdateStore input.m_OpenTime").val( "" );
				
				$("#m_StoreInput>table.m_UpdateStore input.m_PointX").val( "" );
				$("#m_StoreInput>table.m_UpdateStore input.m_PointY").val( "" );
			
				$("#m_StoreInput>table.m_UpdateStore textarea.m_Desc").val( "" );
				$("#m_UserList>table.m_UserList tr.current").remove();
				*/
			});
		}
	}
	
	$(function() {
		$.NewStore.Init();
	});
})(jQuery);

</script>
</asp:Content>
